﻿<?xml version="1.0" encoding="utf-8" ?>

<cls:class
	name="Image"
	type="http://metalx.org/Video/Graphics/Image"
	static="true"
	xmlns="http://metalx.org/Program"
	xmlns:cls="http://metalx.org/Class"
	xmlns:var="http://metalx.org/Variable"
	xmlns:clsf="http://metalx.org/i386/Functions/Class"
	xmlns:sys="http://metalx.org/i386/Functions/System"
	xmlns:cat="http://metalx.org/i386/Functions/Catalog"
	xmlns:obj="http://metalx.org/i386/Functions/Object"
	xmlns:mm="http://metalx.org/i386/Functions/MemoryManager"
	xmlns:bool="http://metalx.org/i386/Functions/Boolean"
	xmlns:str="http://metalx.org/i386/Functions/String"
	xmlns:int="http://metalx.org/i386/Functions/Integer"
	xmlns:hex="http://metalx.org/i386/Functions/Hexadecimal"
	xmlns:con="http://metalx.org/i386/Functions/Console"
	xmlns:math="http://metalx.org/Intel/80386/Math"
	xmlns:ari="http://metalx.org/Intel/80386/Arithmetic"
	xmlns:shift="http://metalx.org/Intel/80386/Shift"
	xmlns:imm="http://metalx.org/Intel/80386/Immediate"
	xmlns:index="http://metalx.org/Intel/80386/Index"
	xmlns:cpu="http://metalx.org/Intel/80386/Operators"
	xmlns:op="http://metalx.org/Intel/80386/Operands">

	<cls:field name="Width" type="http://metalx.org/Integer" offset="0"/>
	<cls:field name="Height" type="http://metalx.org/Integer" offset="4"/>
	<cls:field name="Size" type="http://metalx.org/Video/Graphics/Size" offset="0"/>

	<cls:method name="Create" type="http://metalx.org/Video/Graphics/Image" static="true">
		<cls:parameter name="Width" type="http://metalx.org/Integer"/>
		<cls:parameter name="Height" type="http://metalx.org/Integer"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>4</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:CX-SIAddress/>

		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:PushAXToStack/>

		<cpu:ArithmeticDXAXOperandFunction/>
		<ari:MultiplyByCXRegister/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>4</byte>

		<cpu:AddImmediateToAX/>
		<int>8</int>

		<cpu:PushAXToStack/>

		<mm:CheckOut/>

		<cpu:CopyRegisterToOperand/>
		<op:CX-DIAddress/>

		<cpu:CopyOperandToRegister/>
		<op:AX-IndexAddressPlusImmediate8/>
		<index:SP/>
		<byte>4</byte>

		<cpu:CopyRegisterToOperand/>
		<op:AX-DIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:PullAXFromStack/>

		<obj:Create/>

		<cpu:PullAXFromStack/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="Flower" type="http://metalx.org/Video/Graphics/Image" static="true">
		<cpu:CopyImmediateToDI/>
		<hex>00400000</hex>

		<obj:Create length="1032" />

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="DrawPoint" type="http://metalx.org/Video/Oracle/VirtualBox">
		<cls:parameter name="Point" type="http://metalx.org/Video/Graphics/Point"/>
		<cls:parameter name="Color" type="http://metalx.org/Video/Graphics/Color"/>

		<cpu:PushDIToStack/>

		<!--Get Size-->
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:PushSIToStack/>

		<cpu:CopyOperandToRegister/>
		<op:BX-SIAddress/>

		<!--Get Point-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>4</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ArithmeticDXAXOperandFunction/>
		<ari:MultiplyByBXRegister/>

		<cpu:AddOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>2</byte>

		<cpu:AddImmediateToAX/>
		<int>8</int>

		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:SI-SIAddress/>

		<cpu:PullDIFromStack/>

		<cpu:AddRegisterToOperand/>
		<op:AX-DIRegister/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIAddress/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToBPRegister/>
		<byte>8</byte>

		<cpu:PullDIFromStack/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="DrawHorizontalLine" type="http://metalx.org/Video/Graphics/Image">
		<cls:parameter name="Line" type="http://metalx.org/Video/Graphics/Line"/>
		<cls:parameter name="Color" type="http://metalx.org/Video/Graphics/Color"/>

		<cpu:PushDIToStack/>

		<!--Get Size-->
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:BX-SIAddress/>

		<!--Get Line-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>4</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ArithmeticDXAXOperandFunction/>
		<ari:MultiplyByBXRegister/>

		<cpu:AddOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>2</byte>

		<cpu:AddImmediateToAX/>
		<int>8</int>

		<cpu:AddRegisterToOperand/>
		<op:AX-DIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:CX-SIAddressPlusImmediate8/>
		<byte>8</byte>

		<!--Get Color-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:Repeat/>
		<cpu:CopyAXToDIAddressAndIncrementDI/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToBPRegister/>
		<byte>8</byte>

		<cpu:PullDIFromStack/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="DrawVerticalLine" type="http://metalx.org/Video/Oracle/VirtualBox">
		<cls:parameter name="Line" type="http://metalx.org/Video/Graphics/Line"/>
		<cls:parameter name="Color" type="http://metalx.org/Video/Graphics/Color"/>

		<cpu:PushDIToStack/>

		<!--Get Size-->
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:BX-SIAddress/>

		<!--Get Line-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>4</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ArithmeticDXAXOperandFunction/>
		<ari:MultiplyByBXRegister/>

		<cpu:AddOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>2</byte>

		<cpu:AddImmediateToAX/>
		<int>8</int>

		<cpu:AddRegisterToOperand/>
		<op:AX-DIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:CX-SIAddressPlusImmediate8/>
		<byte>8</byte>

		<!--Get Color-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftBXRegisterLeft/>
		<byte>2</byte>
		
		<label id="forEachPixel"/>

		<cpu:CopyRegisterToOperand/>
		<op:AX-DIAddress/>

		<cpu:AddRegisterToOperand/>
		<op:BX-DIRegister/>

		<cpu:LoopToRelative8/>
		<addressOf ref="forEachPixel" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToBPRegister/>
		<byte>8</byte>

		<cpu:PullDIFromStack/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="FillRectangle" type="http://metalx.org/Video/Oracle/VirtualBox">
		<cls:parameter name="Rectangle" type="http://metalx.org/Video/Graphics/Rectangle"/>
		<cls:parameter name="Color" type="http://metalx.org/Video/Graphics/Color"/>

		<cpu:PushDIToStack/>

		<!--Get Size-->
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:BX-SIAddress/>

		<!--Get Rectangle-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>4</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ArithmeticDXAXOperandFunction/>
		<ari:MultiplyByBXRegister/>

		<cpu:AddOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>2</byte>

		<cpu:AddImmediateToAX/>
		<int>8</int>

		<cpu:AddRegisterToOperand/>
		<op:AX-DIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:CX-SIAddressPlusImmediate8/>
		<byte>8</byte>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddressPlusImmediate8/>
		<byte>12</byte>

		<!--Get Color-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftBXRegisterLeft/>
		<byte>2</byte>

		<label id="forEachRow"/>

		<cpu:PushCXToStack/>
		<cpu:PushDIToStack/>

		<cpu:Repeat/>
		<cpu:CopyAXToDIAddressAndIncrementDI/>

		<cpu:PullDIFromStack/>
		<cpu:PullCXFromStack/>

		<cpu:AddRegisterToOperand/>
		<op:BX-DIRegister/>

		<cpu:DecrementDX/>

		<cpu:BranchToRelative8IfNotZero/>
		<addressOf ref="forEachRow" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToBPRegister/>
		<byte>8</byte>

		<cpu:PullDIFromStack/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="DrawImage" type="http://metalx.org/Video/Oracle/VirtualBox">
		<cls:parameter name="Image" type="http://metalx.org/Video/Graphics/Image"/>
		<cls:parameter name="Point" type="http://metalx.org/Video/Graphics/Point"/>

		<cpu:PushDIToStack/>

		<!--Get Size-->
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:BX-SIAddress/>

		<!--Get Point-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ArithmeticDXAXOperandFunction/>
		<ari:MultiplyByBXRegister/>

		<cpu:AddOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>2</byte>

		<cpu:AddImmediateToAX/>
		<int>8</int>

		<cpu:AddRegisterToOperand/>
		<op:AX-DIRegister/>

		<!--Get Image-->
		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>4</byte>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:CX-SIAddress/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToSIRegister/>
		<byte>8</byte>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftBXRegisterLeft/>
		<byte>2</byte>

		<label id="forEachRow"/>

		<cpu:PushCXToStack/>
		<cpu:PushDIToStack/>

		<cpu:Repeat/>
		<cpu:CopySIAddressToDIAddressAndIncrementSIAndDI/>

		<cpu:PullDIFromStack/>
		<cpu:PullCXFromStack/>

		<cpu:AddRegisterToOperand/>
		<op:BX-DIRegister/>

		<cpu:DecrementDX/>

		<cpu:BranchToRelative8IfNotZero/>
		<addressOf ref="forEachRow" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToBPRegister/>
		<byte>8</byte>

		<cpu:PullDIFromStack/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="SetColor" type="http://metalx.org/Video/Graphics/Image">
		<cls:parameter name="Color" type="http://metalx.org/Video/Graphics/Color"/>

		<cpu:PushDIToStack/>

		<!--Get Size-->
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDIRegister/>
		<byte>8</byte>

		<cpu:CopyOperandToRegister/>
		<op:BX-SIAddress/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ArithmeticDXAXOperandFunction/>
		<ari:MultiplyByBXRegister/>

		<cpu:ShiftRegisterByOneFunction/>
		<shift:ShiftAXRegisterRight/>

		<cpu:CopyRegisterToOperand/>
		<op:AX-CXRegister/>

		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<obj:GetData/>

		<cpu:CopySIAddressToAXAndIncrementSI/>

		<cpu:PushAXToStack/>
		<cpu:PushAXToStack/>

		<cpu:ExtendedOperator/>
		<ext:CopyOperandToMmxRegister64 xmlns:ext="http://metalx.org/Intel/80386/ExtendedOperators"/>
		<mmx:MM0-IndexAddress xmlns:mmx="http://metalx.org/Intel/80386/MmxOperands"/>
		<index:SP/>

		<label id="nextPixel"/>

		<cpu:ExtendedOperator/>
		<ext:CopyMmxRegisterToOperand64 xmlns:ext="http://metalx.org/Intel/80386/ExtendedOperators"/>
		<mmx:MM0-DIAddress xmlns:mmx="http://metalx.org/Intel/80386/MmxOperands"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDIRegister/>
		<byte>8</byte>

		<cpu:LoopToRelative8/>
		<addressOf ref="nextPixel" type="Relative8"/>

		<cpu:PullDIFromStack/>
		<cpu:PullDIFromStack/>
		<cpu:PullDIFromStack/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToBPRegister/>
		<byte>4</byte>

		<cls:return/>
	</cls:method>

	<cls:method name="GetSize" type="http://metalx.org/Video/Graphics/Size">
		<cls:return/>
	</cls:method>

	<cls:method name="ToString" type="http://metalx.org/String">
		<cpu:CopyImmediateToDI/>
		<addressOf ref="image" type="Absolute32"/>

		<str:CreateObject/>

		<cpu:ReturnToNearCaller/>

		<var:string id="image">Image</var:string>
	</cls:method>

	<cls:method name="GetClass" type="http://metalx.org/Class">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetType/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<clsf:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetClass" type="http://metalx.org/Class" static="true">
		<cpu:CopyRegisterToOperand/>
		<op:BX-DIRegister/>

		<clsf:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>
</cls:class>